package com.xuzz.study.io.nio;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class NioFileChannel2 {
    public static void main(String[] args) throws Exception  {
        FileInputStream fileInputStream = new FileInputStream("G:\\study\\JavaStudy\\file01.txt");
        FileChannel channel = fileInputStream.getChannel();
        ByteBuffer allocate = ByteBuffer.allocate(1024);

        while(true)
        {
            int read = channel.read(allocate);
            allocate.flip();
            if(read==-1)
            {
                break;
            }
            System.out.println((char)(allocate.get()));
            allocate.clear();
        }
        fileInputStream.close();
        channel.close();
    }
}
